package com.imgpro.controller;

import com.imgpro.Constant.MessageConstant;
import com.imgpro.Exception.SignUpFailedException;
import com.imgpro.Properties.JwtProperties;
import com.imgpro.Result.Result;
import com.imgpro.dto.UserDTO;
import com.imgpro.mapper.UserMapper;
import com.imgpro.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "用户功能的接口")
@RequestMapping("/user")
public class UserController {
    @Autowired
    private JwtProperties jwtProperties;

    @Autowired
    private UserService userService;

    @ApiOperation(value = "展示用户信息")
    @GetMapping("/user")
    public Result<UserDTO> showUser(HttpServletRequest request){

        String token = request.getHeader(jwtProperties.getAdminTokenName());

        UserDTO userDTO = userService.showUser(token);


        return Result.success(userDTO);
    }


    @ApiOperation(value = "修改一个用户信息")
    @PostMapping("/update")
    public Result<UserDTO> updateUser(HttpServletRequest request, @RequestBody UserDTO userDTO) throws Exception{



        String token = request.getHeader(jwtProperties.getAdminTokenName());

        userService.updateUser(token, userDTO);

        return Result.success();
    }



}
